package com.shop.filter; /**
 * ${PACKAGE_NAME}文档说明
 *
 * @author Angluzha
 * @version 2022/9/17
 */

import com.shop.entity.User;
import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebFilter(filterName = "Filter_03_Permission",value = {"/back/userjsp/*","/back/main.jsp"})
public class Filter_03_Permission implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        User user = (User) req.getSession().getAttribute("user");
        if (user.getStatus()>1) {
            chain.doFilter(request, response);
        }else {
            resp.sendRedirect("/login.jsp");
        }
    }
}
